package com.mfangsoft.zhuangjialong.integration.taskpush.controller;

import java.text.ParseException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.taskpush.model.BaseTaskPush;
import com.mfangsoft.zhuangjialong.integration.taskpush.service.TaskPushService;


@Controller
@RequestMapping("/server")
public class TaskPushController {
	
	@Autowired
	private TaskPushService taskPushService;
	
	/**
	 * 任务分配表新增
	 * @param 
	 * @return
	 */
	
	@RequestMapping(value="/addTaskPush",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addTaskPush(@RequestBody BaseTaskPush baseTaskPush){
		ResponseMessage<String> message = new ResponseMessage<String>();
	
		//baseActivityInfo.setCreater((String) session.getAttribute("user"));
		/*System.out.println(UserContext.getCurrentUser());
		System.out.println(UserContext.getCurrentUser().getUserInfoEntity().getName());*/
		try {
			
			taskPushService.addTaskPush(baseTaskPush);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;

	}
	/**
	 * 任务分配表列表
	 * @param 
	 * @return
	 */

	@RequestMapping(value="/selectTaskPush",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public Page<BaseTaskPush> selectTaskPush(@RequestBody Page<BaseTaskPush> page){

		return  taskPushService.selectTaskPush(page);

	}
	/**
	 * 任务分配表导购
	 * @param 
	 * @return
	 * @throws  
	 */
	@RequestMapping(value="/updateTaskPushOne",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseTaskPush> updateTaskPushOne(@RequestBody BaseTaskPush baseTaskPush) throws ParseException{
		
		ResponseMessage<BaseTaskPush> message = new ResponseMessage<BaseTaskPush>();
		/*BaseActivityInfo baseActivityInfo = new BaseActivityInfo();
		baseActivityInfo.setId(25);*/
		try {
			//tagService.updateGiftOne(baseTag);
			taskPushService.updateTaskPushOne(baseTaskPush);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 删除任务分配表
	 * @param 
	 * @return
	 * @throws  
	 */
	
	@RequestMapping(value="/deleteTaskPushOne/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public  ResponseMessage<BaseTaskPush> deleteTaskPushOne(@PathVariable int id) throws ParseException{
		
		ResponseMessage<BaseTaskPush> message = new ResponseMessage<BaseTaskPush>();
		try {
		//	tagService.deleteTagOne(id);
			taskPushService.deleteTaskPushOne(id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
}
